﻿using UnityEngine;
using UnityEngine.UI;

public class RemoteLoader : MonoBehaviour {

    #region 单例

    public static RemoteLoader Instance
    {
        get
        {
            if (_instance != null) return _instance;
            GameObject go = GameObject.Find("Canvas/ButtonPanel");
            _instance = go.GetComponent<RemoteLoader>();
            return _instance;
        }
    }
    private static RemoteLoader _instance;

    #endregion

    public RemoteControl RemoteCtrl;

    public GameObject Cube;
    public Button PosXBtn;
    public Button PosYBtn;
    public Button PosZBtn;

    public Button ColorRedBtn;
    public Button ColorGreenBtn;
    public Button ColorBlueBtn;

    void Start()
    {
        this.RemoteCtrl = this.transform.GetComponent<RemoteControl>();
        this.PosXBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new MoveCommand(this.Cube.transform, Vector3.right));
        });

        this.PosYBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new MoveCommand(this.Cube.transform, Vector3.up));
        });

        this.PosZBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new MoveCommand(this.Cube.transform, Vector3.forward));
        });

        this.ColorRedBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new ColorChangeCommand(Color.red, this.Cube.GetComponent<Renderer>().material));
        });

        this.ColorGreenBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new ColorChangeCommand(Color.green, this.Cube.GetComponent<Renderer>().material));
        });

        this.ColorBlueBtn.onClick.AddListener(() =>
        {
            this.RemoteCtrl.SetCommand(new ColorChangeCommand(Color.blue, this.Cube.GetComponent<Renderer>().material));
        });
    }
}
